package com.charlotte.study.gupao.flyweight.general;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author junjie.ding
 * @date 2020/3/9
 */
public class FlyweightFactory {

    // 存放缓存对象
    private static Map<String, IFlyweight> pool = new ConcurrentHashMap<>();

    public static IFlyweight getFlyweightBean(String intrinsicState){
        if(!pool.containsKey(intrinsicState)){
            IFlyweight concreteFlyweight = new ConcreteFlyweight(intrinsicState);
            pool.put(intrinsicState, concreteFlyweight);
        }
        return pool.get(intrinsicState);
    }

}
